package com.juc.completionService.completionService5;

import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Run4 {

	public static void main(String[] args) throws InterruptedException {
		MyCallableA callableA = new MyCallableA();
		MyCallableB callableB = new MyCallableB();
		ExecutorService executorService = Executors.newSingleThreadExecutor();
		CompletionService csRef = new ExecutorCompletionService<>(executorService);
		csRef.submit(callableA);
		csRef.submit(callableB);
		
		for (int i = 0; i < 2; i++) {
			System.out.println("zzzzzzzzzzzz " + csRef.poll());
		}
		Thread.sleep(6000);
		System.out.println(" A处  " + csRef.poll());
		System.out.println(" B处  " + csRef.poll());
		System.out.println(" main end! ");
	}
}
